#ifndef IMPORTNM_H
#define IMPORTNM_H

#pragma interface

#include <boost/preprocessor/repetition.hpp>
#include <boost/preprocessor/arithmetic/sub.hpp>
#include <boost/preprocessor/punctuation/comma_if.hpp>
#include <boost/preprocessor/punctuation/comma.hpp>
#include <boost/preprocessor/punctuation/paren.hpp>
#include <boost/preprocessor/control/expr_if.hpp>
#include <boost/preprocessor/facilities/empty.hpp>
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/logical/not.hpp>
#include <map>
#include "jncFntHandlerDb.h"

// Register object properties

#define OUTPUTARGLIST(z, n, data) data

#define EXPR     (gReturnCode)( T::*Cbextractor)

#define EXP_CONS							\
  BOOST_PP_EXPR_IF(BOOST_PP_NOT(IN__CONS__),BOOST_PP_SEQ_ELEM(0, EXPR))	\
    BOOST_PP_EXPR_IF(BOOST_PP_NOT(IN__CONS__),				\
		     (BOOST_PP_EXPR_IF(BOOST_PP_NOT(IN__CONS__),BOOST_PP_SEQ_ELEM(1, EXPR))) \
		     )							\
    BOOST_PP_EXPR_IF(BOOST_PP_NOT(IN__CONS__),( ))			\
    BOOST_PP_COMMA_IF(BOOST_PP_NOT(IN__CONS__))

/*     BOOST_PP_EXPR_IF(IN__CONS__,BOOST_PP_RPAREN())			\ */

#define REGISTOBJDCL(z, n, data)						\
  template<class T>							\
  void									\
  exportObjectHandle(							\
		     T* o, const char* tag[JINC_MAX_ARG], jncTypei typ[JINC_MAX_ARG], \
		     EXP_CONS \
		     gReturnCode (T::*Cblauncher)(BOOST_PP_ENUM(n, OUTPUTARGLIST,jncTypev)), \
		     Priority level)

/* BOOST_PP_REPEAT(JINC_MAX_ARG, REGISTOBJDCL, ~) */

#include "jncImportNamespace.cpp"

#define REGISTOBJDEF(z, n, data)     \
  REGISTOBJDCL(z, n, data)	     \
       REGISTOBJBODY(z, n, data)

#ifndef IN__CONS__
#define IN__CONS__     1  // Register object constructor
BOOST_PP_REPEAT(JINC_MAX_ARG, REGISTOBJDEF, T)
#endif
#undef IN__CONS__
  
/* #ifndef IN__CONS__   // Register object member functions */
/* #define IN__CONS__     0 */
/* BOOST_PP_REPEAT(JINC_MAX_ARG, REGISTOBJDEF, T) */

/* template<class T> */
/* void registerProperties(const char* str[][JINC_MAX_ARG], const jncTypei type[][JINC_MAX_ARG], gnCallback callback[][2], Priority p[][1]) { */
/*   std::list<std::string> fn_sb; */
/*   for(int i = 0; str[i][0] != NULL; i++) { */
/*     char* tmp = str[i][0]; */
/*     while(tmp) { */
/*       fn_sb.push_back(tmp); */
/*       ++tmp; */
/*     } */
/*     std::list<jncTypei> fn_type(fn_sb.size()); */
/*     std::copy(type[i][0], type[i][fn_type.size()-1], fn_type.begin()); */
/*     if(callback[i][0]) */
/*       exportObjectHandle(new T(), fn_sb, fn_type, callback[i][0], callback[i][1], p[i][0]); */
/*     else */
/*       exportObjectHandle(new T(), fn_sb, fn_type, callback[i][1], p[i][0]); */
/*     fn_sb.clear(); */
/*   } */
/* } */


/* #endif */

#endif
